<template>

</template>

<script>
    import env from '@config/env'

    var isPageHide = false;
    window.addEventListener('pageshow', function () {
        if (isPageHide) {
            window.location.reload()
        }
    })
    window.addEventListener('pagehide', function () {
        isPageHide = true
    })
    export default {
        name: "auth",
        data() {
            return {
                appid: env.WX_APPID
            }
        },
        mounted() {
            let param=window.location.search
            let redirect_uri = param.split('?redirect_uri=')[1]
            let auth_uri = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid={appid}&redirect_uri={redirect_uri}&response_type=code&scope=snsapi_base#wechat_redirect'
            if (redirect_uri) {
                redirect_uri = window.btoa(unescape((redirect_uri)))
                let callback = `${window.location.protocol}//${window.location.hostname}/frontend/ihub/callback?redirect=${redirect_uri}`
                window.location.replace(auth_uri.replace('{appid}', this.appid).replace('{redirect_uri}', callback))
            } else {
                alert('redirect_url 为空')
                return
            }
        }
    }
</script>

<style scoped>

</style>